package com.zy.design.demo.behavioral;

/**
 * 状态模式
 * 特点：对象根据状态行为改变。
 * 状态模式更关注对象的状态管理，随着状态变化改变行为。
 */
interface State {
    void handle();
}

class HappyState implements State {
    public void handle() { System.out.println("开心状态：笑出声"); }
}

class SadState implements State {
    public void handle() { System.out.println("悲伤状态：默默流泪"); }
}

class Context {
    private State state;

    public void setState(State state) { this.state = state; }

    public void request() { state.handle(); }
}

class Main1 {
    public static void main(String[] args) {
        Context context = new Context();
        context.setState(new HappyState());
        context.request();

        context.setState(new SadState());
        context.request();
    }
}
